//
//  KLHomeViewController.swift
//  新浪微博
//
//  Created by WTFKL on 17/8/4.
//  Copyright © 2017年 WTF. All rights reserved.
//

import UIKit

private let cellID = "cellID";

class KLHomeViewController: KLBaseViewController {
   fileprivate lazy var statusData = [String]();

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    //点击事件
   @objc fileprivate func click(){
        let vc = KLBaseViewController();
        vc.view.backgroundColor = #colorLiteral(red: 0.9098039269, green: 0.4784313738, blue: 0.6431372762, alpha: 1);
        navigationController?.pushViewController(vc, animated: true);
    }
    //模拟加载数据
    override func loadData() {
        
        let urlString = "https://api.weibo.com/2/statuses/home_timeline.json";
        let param = ["access_token" : "2.00QqAr1EjehO6Cd7cd5ca09bRpT5VE"];
        
        
        KLNetworkManager.shared.get(urlString, parameters: param, progress: nil, success: { (URLSessionDataTask, kl_json) in
            print(kl_json ?? "");
        }) { (URLSessionDataTask, Error) in
            print(Error);
        }
        
        guard let tableV = tableV else {return}
        tableV.reloadData();
        tableV.mj_header.endRefreshing();
        tableV.mj_footer.endRefreshing();
    }
    
}



extension KLHomeViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        //print(statusData.count);
        return statusData.count;
    }
    
  
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var cell = tableView.dequeueReusableCell(withIdentifier: cellID);
        
        if cell == nil {
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellID);
        }
        
        cell?.textLabel?.text = statusData[indexPath.row];
        
        return cell!;
    }
    
    override func addTableView() {
        super.addTableView();
        let barbtn = UIBarButtonItem(title: "好友", style: .plain, target: self, action: #selector(click), normalTextColor: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), highLightTextColor: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1) ,isBack : false);
        navItem.rightBarButtonItem = barbtn;
    }
}


